﻿using System;
using System.Windows.Data;
using System.Globalization;

namespace OverlakeApp.Converters
{
    /// <summary>
    /// Converts from ticks to a timespan.
    /// </summary>
    public class TicksToTimespanConverter : IValueConverter
    {
        /// <summary>
        /// Converts from ticks to a timespan.
        /// </summary>
        /// <param name="value">The timespan in ticks, as a long.</param>
        /// <param name="targetType">Not used.</param>
        /// <param name="parameter">Not used.</param>
        /// <param name="culture">Not used.</param>
        /// <returns>The tick value as a timespan.</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is long))
                return null;

            return TimeSpan.FromTicks((long)value);
        }

        /// <summary>
        /// Not implemented.
        /// </summary>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
